import {actions, ReduxService} from "@/core/redux_service";

const  CHANGE_NAME = "CHANGE_NAME";
export type CHANE_NAME_TYPE = typeof CHANGE_NAME;

export interface DemoService_CHANGE_NAME{
    type:CHANE_NAME_TYPE,
    name:string
}

export interface IDemoService {
    name:string
}

export type DemoService_Modfily = DemoService_CHANGE_NAME;

export  class DemoService extends ReduxService{

    static initState:IDemoService = {
        name:"1"
    };

    @actions()
    changeMinWindow(name:string):DemoService_CHANGE_NAME{
        return {
            type: CHANGE_NAME,
            name
        }
    };

    static reducers = (state:IDemoService = DemoService.initState, action:DemoService_Modfily):IDemoService => {
        if (action.type === "CHANGE_NAME") {
            return {
                ...state,
                name: action.name
            }
        }
        return state;
    }
}
